﻿using System;
using System.Drawing;

namespace Sustainalytics.ReportGenerator.BL
{
    public class HistoricalPerformanceChartTemplate : Dundas.Charting.WinControl.Chart
    {
        public HistoricalPerformanceChartTemplate(int width, int height, bool calibration)
        {
            var axisXMinimum = DateTime.Now.AddMonths(-36).ToOADate();
            var axisXMaximum = DateTime.Now.ToOADate();

            Palette = Dundas.Charting.WinControl.ChartColorPalette.Dundas;
            Size = new Size(width, height);
            BackGradientEndColor = Color.Transparent;
            BorderLineColor = Color.Transparent;
            BorderLineWidth = 0;
            AlwaysRecreateHotregions = true;

            var calibri10RegularFont = new Font("Calibri", 10, FontStyle.Regular, GraphicsUnit.Point, 1, false);
            var calibri12RegularFont = new Font("Calibri", 12, FontStyle.Regular, GraphicsUnit.Point, 1, false);

            var chartArea = new Dundas.Charting.WinControl.ChartArea
            {
                BackColor = Color.Transparent,
                BackGradientEndColor = Color.Transparent,
                ShadowColor = Color.Transparent,
                BorderColor = calibration ? Color.Blue : Color.Transparent,
                BorderStyle = Dundas.Charting.WinControl.ChartDashStyle.Solid,
                Name = "ChartArea2",
                Position = { Auto = false, X = 0, Y = 0, Width = 100, Height = 100 },
                InnerPlotPosition =
                {
                    Auto = true,
                },
                AxisY =
                {
                    LineWidth = 2,
                    LineColor = Color.Black,
                    LabelsAutoFit = true,
                    LabelsAutoFitMinFontSize = 10,
                    StartFromZero = true,
                    Minimum = 20,
                    Maximum = 100,
                    MajorGrid =
                    {
                        Enabled = true,
                        Interval = 20,
                        IntervalType = Dundas.Charting.WinControl.DateTimeIntervalType.Number,
                        LineColor = Color.FromArgb(64, 64, 64, 64)
                    },
                    MajorTickMark =
                    {
                        Enabled = true,
                        Interval = 20,
                        IntervalType = Dundas.Charting.WinControl.DateTimeIntervalType.Number,
                        Style = Dundas.Charting.WinControl.TickMarkStyle.Outside,
                        Size = 0.5f,
                        LineColor = Color.Black,
                    },
                    LabelStyle =
                    {
                        Enabled = true,
                        Format = "N0",
                        Interval = 20,
                        IntervalType = Dundas.Charting.WinControl.DateTimeIntervalType.Number,
                        Font = calibri10RegularFont,
                        FontColor = Color.Black,
                    }
                },
                AxisX =
                {
                    LineColor = Color.Black,
                    LineWidth = 3,
                    LabelsAutoFit = true,
                    TitleFont = calibri10RegularFont,
                    StartFromZero = false,
                    Minimum = axisXMinimum,
                    Maximum = axisXMaximum,
                    MajorGrid =
                    {
                        Enabled = false,
                        Interval = 1,
                        IntervalType = Dundas.Charting.WinControl.DateTimeIntervalType.Years,
                        LineColor = Color.FromArgb(64, 64, 64, 64)
                    },
                    MinorTickMark =
                    {
                        Enabled = true,
                        Interval = 1,
                        IntervalOffsetType = Dundas.Charting.WinControl.DateTimeIntervalType.Number,
                        IntervalType = Dundas.Charting.WinControl.DateTimeIntervalType.Years,
                        Style = Dundas.Charting.WinControl.TickMarkStyle.Outside,
                        LineColor = Color.Black,
                        Size = 3f
                    },
                    LabelStyle =
                    {
                        Enabled = true,
                        Interval = 1,
                        IntervalType = Dundas.Charting.WinControl.DateTimeIntervalType.Years,
                        IntervalOffset = 0.5,
                        IntervalOffsetType = Dundas.Charting.WinControl.DateTimeIntervalType.Years,
                        Format = "yyyy",
                        Font = calibri12RegularFont,
                        FontColor = Color.Black
                    }
                },
            };

            ChartAreas.Add(chartArea);

            var series2Series = new Dundas.Charting.WinControl.Series
            {
                ChartArea = "ChartArea2",
                Type = Dundas.Charting.WinControl.SeriesChartType.Line,
                Color = Color.FromArgb(255, 157, 214, 197),
                BorderWidth = 5,
                CustomAttributes =
                    "PointWidth=1.0, ColumnLabelStyle=Horizontal, DrawingStyle=Default, LabelStyle=Auto, DrawSideBySide=Auto",
                Name = "Series2",
                Font = calibri10RegularFont,
                XValueType = Dundas.Charting.WinControl.ChartValueTypes.DateTime,
                YValueType = Dundas.Charting.WinControl.ChartValueTypes.Double,
                ShadowOffset = 0,
                ShowLabelAsValue = false,
                ShowInLegend = false,
                LegendText = "Series2"
            };
            Series.Add(series2Series);

            var series3Series = new Dundas.Charting.WinControl.Series
            {
                ChartArea = "ChartArea2",
                Type = Dundas.Charting.WinControl.SeriesChartType.Line,
                Color = Color.FromArgb(255, 25, 116, 106),
                BorderWidth = 5,
                CustomAttributes =
                    "PointWidth=1.0, ColumnLabelStyle=Horizontal, DrawingStyle=Default, LabelStyle=Auto, DrawSideBySide=Auto",
                Name = "Series3",
                Font = calibri10RegularFont,
                XValueType = Dundas.Charting.WinControl.ChartValueTypes.DateTime,
                YValueType = Dundas.Charting.WinControl.ChartValueTypes.Double,
                ShadowOffset = 0,
                ShowLabelAsValue = false,
                ShowInLegend = false,
                LegendText = "Series3"
            };

            Series.Add(series3Series);

            var series4Series = new Dundas.Charting.WinControl.Series
            {
                ChartArea = "ChartArea2",
                Type = Dundas.Charting.WinControl.SeriesChartType.Line,
                BorderStyle = Dundas.Charting.WinControl.ChartDashStyle.Dot,
                Color = Color.FromArgb(255, 252, 175, 23),
                BorderWidth = 5,
                CustomAttributes =
                    "PointWidth=1.0, ColumnLabelStyle=Horizontal, DrawingStyle=Default, LabelStyle=Auto, DrawSideBySide=Auto",
                Name = "Series4",
                Font = calibri10RegularFont,
                XValueType = Dundas.Charting.WinControl.ChartValueTypes.DateTime,
                YValueType = Dundas.Charting.WinControl.ChartValueTypes.Double,
                ShadowOffset = 0,
                ShowLabelAsValue = false,
                ShowInLegend = false,
                LegendText = "Series4"
            };

            Series.Add(series4Series);
        }
    }
}
